<?php

namespace App\Services\Admin\Users;

use App\Daos\Admin\Users\GroupDao;

class GroupService
{
    public static function groupList ($size,$offset){
        if (!is_numeric($size)){
            throw new \Exception('分页传参错误');
        }
        $res = GroupDao::groupList($size,$offset);
        if (!$res){
            throw new \Exception('数据获取失败');
        }
        return $res;
    }

    public static function groupAdd ($name){
        $res = GroupDao::groupAdd($name);
        if (!$res){
            throw new \Exception('添加失败');
        }
        return $res;
    }

    public static function groupUpdate ($data){
        $res = GroupDao::groupUpdate($data);
        if (!$res){
            throw new \Exception('修改失败');
        }
        return $res;
    }

    public static function groupDelete ($id){
        if (!is_numeric($id)){
            throw new \Exception('传参错误');
        }
        $res = GroupDao::groupDelete($id);
        if (!$res){
            throw new \Exception('删除失败');
        }
        return $res;
    }

    public static function sendGroup ($userid,$group){
        $userid = explode(',',substr($userid,0,-1));
        $res = GroupDao::sendGroup($userid,$group);
        if (!$res){
            throw new \Exception('设置分组失败');
        }
        return true;
    }
}
